package com.iman.Confucius.web.student;

 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.lf5.util.ResourceUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

 
import com.alibaba.fastjson.JSONObject;
import com.iman.Confucius.domain.User;
import com.iman.Confucius.service.student.ClassService;
import com.iman.Confucius.vo.CaseVo;
import com.iman.Confucius.vo.student.ClassVo;
import com.iman.Confucius.web.BaseController;
import com.iman.common.support.Page;
import com.iman.common.util.ConfigUtil;

 

/**
 * *************************************************************************
 * @文件名称: MyCalssController.java
 *
 * @包路径  : com.iman.Confucius.web.student 
 *				 
 * @版权所有:   TSW   科技有限公司 (C) 2014
 *
 * @类描述:   我的班级
 * 
 * @创建人:   wangxiaolei  
 *
 * @创建时间: 2014年12月18日 - 上午1:55:57 
 *
 * @修改记录:
   -----------------------------------------------------------------------------------------------
             时间						|		修改人		|		修改的方法		|		修改描述                                                                
   -----------------------------------------------------------------------------------------------
							|					|					|                                       
   ----------------------------------------------------------------------------------------------- 	
 
 **************************************************************************
 */


@Controller
@RequestMapping(value="/student/class/*")
public class MyCalssController  extends BaseController {
	
	@Autowired
	private ClassService classServiceImpl;
	
	/**
	 * 
	 *  Function:
	 *  功能说明：
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2014年12月16日 下午2:59:30
	 *	返回类型: ModelAndView    
	 *  @param request
	 *  @param menu
	 *  @return
	 */
	@RequestMapping(value="/init")
	public ModelAndView initMyClass(HttpServletRequest request ){
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("userid", getUserIdInSession(request).toString() ); 
		ModelAndView view =null;
		view = new ModelAndView("student/my_class",model);
		List<ClassVo>  vos  =classServiceImpl.getStudentClass(model);  
       view.addObject("classes",vos);
       view.addObject("spaceurl",  ConfigUtil.getString("drmspaceUrl"));
    
		putResourceSrc(  view);
		
		return view;
	} 
	 
	/**
	 * 获取班级的所有学员
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value="/getStudents")
	public ModelAndView initMyClass(HttpServletRequest request,HttpServletResponse response ) throws IOException{
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("classid", request.getParameter("classid")); 
		model.put("pn", request.getParameter("pn"));
		model.put("ps", request.getParameter("ps"));
  		//List<User>  vos  =classServiceImpl.getStudents(model);
		Page<User>  vos  =classServiceImpl.getStudentsPage(model);
  		
 		JSONObject json = new JSONObject();
		json.put("users", vos.getData());
		json.put("pc", vos.getTotalPageCount());
 	 
		response.setContentType("text/html;charset=utf-8");
		PrintWriter print = response.getWriter();
		print.print(json);
		print.flush();
		print.close();
		return null;
	} 

}
